package com.xiaoma.config.config;

import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import javax.annotation.Resource;

//@Configuration
public class RedisConfig {
    
    // 将系统自带的RedisTemplate示例转化为 RedisTemplate<String, Object>，如有其他类型的RedisTemplate需求，可自行增加
    @Resource(name = "redisTemplate")
    private RedisTemplate<String, Object> redisTemplate;
    
    @Bean(name = "objRedisTemplate")
    RedisTemplate<String, Object> objRedisTemplate(){
        // key使用string序列化
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        // value采用json序列化
        redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        return redisTemplate;
    }

}

